3 -> 6
6 -> 3
2 -> 6
2 -> 1
1 -> 2
6 -> 1
void compute(MessageIterator msgs) {
if (superstep() >= 1) {
double sum = 0.0;
for (; !msgs->done(); msgs->next()) {
sum += msgs->value();
}
mutableValue = 0.15 / numVertices + 0.85 * sum;
}
if (superstep() < 30) {
const int64 n = getOutEdgeIterator().size();
sendMessageToAllNeighbours(getValue() / n);
} else {
voteToHalt();
}
}
A --1-> C
A --3-> B
C --1-> B
Trace:
SS0.
A = 0
B = infinity
C = infinity
A sends 0+3=3 to B
A sends 0+1=1 to C
SS1.
A = 0
B = 3
C = 1
A is unchanged, votes to halt
C sends 1+1=2 to B
SS2.
A = 0
B = 2
C = 1
A is unchanged, votes to halt
C is unchanged, votes to halt
B has no out neighbours, votes to halt
Done
e.g. for single source shortest path:
void combine(MessageIterator msgs) {
float minDist = infinity;
for (; !msgs->done(); msgs->next()) {
minDist = min(minDist, msgs->value());
}
// output(source_name, value)
output("combined_source", minDist);
}